package Tree;

import java.io.*;
import java.util.Arrays;

/**
 * 删除一条边，在添加一条边，让树的重心唯一
 */
public class LinkCutCentroids {

    public static int MAXN = 10001;

    public static int n;

    public static int[] head = new int[MAXN];

    public static int[] next = new int[MAXN << 1];

    public static int[] to = new int[MAXN << 1];

    public static int cnt;

    // size[i]: 从1号节点开始dfs的过程中，以i为头的子树的节点数
    public static int[] size = new int[MAXN];

    // max sub[i] : 如果节点i做整棵树的根，最大子树的大小
    public static int[] maxsub = new int[MAXN];

    // 收集所有的重心
    public static int[] centers = new int[2];

    // 任何一个叶节点
    public static int anyLeaf;

    // 该叶节点的父亲节点
    public static int anyLeafFather;

    public static void build() {
        cnt = 1;
        Arrays.fill(head, 1, n + 1, 0);
    }

    public static void addEdge(int u, int v) {
        next[cnt] = head[u];
        to[cnt] = v;
        head[u] = cnt++;
    }

    public static void dfs(int u, int f) {
        size[u] = 1;
        maxsub[u] = 0;
        for (int e = head[u], v; e != 0; e = next[e]) {
            v = to[e];
            if (v != f) {
                dfs(v, u);
                size[u] += size[v];
                maxsub[u] = Math.max(maxsub[u], size[v]);
            }
        }
        maxsub[u] = Math.max(maxsub[u], n - size[u]);
    }

    /**
     * 随意找一个叶节点和该叶节点的父亲节点
     *
     * @param u
     * @param father
     */
    public static void find(int u, int father) {
        for (int e = head[u]; e != 0; e = next[e]) {
            if (to[e] != father) {
                find(to[e], u);
                return;
            }
        }
        // 只有叶节点才会满足 e == 0这个跳出条件，执行下面的代码
        anyLeaf = u;
        anyLeafFather = father;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        in.nextToken();

        int testCase = (int) in.nval;

        for (int t = 1; t <= testCase; t++) {
            in.nextToken();
            n = (int) in.nval;
            build();
            for (int i = 1, u, v; i < n; i++) {
                in.nextToken();
                u = (int) in.nval;
                in.nextToken();
                v = (int) in.nval;

                addEdge(u, v);
                addEdge(v, u);
            }
            if (compute() == 1) {
                out.println(centers[0] + " " + to[head[centers[0]]]);
                out.println(centers[0] + " " + to[head[centers[0]]]);
            } else {
                out.println(anyLeafFather + " " + anyLeaf);
                out.println(centers[0] + " " + anyLeaf);
            }
        }
        out.flush();
        out.close();
        br.close();
    }

    /**
     * 返回重心的数量
     * @return 返回重心的数量
     */
    public static int compute() {
        dfs(1, 0);
        int m = 0;
        for (int i = 1; i <= n; i++) {
            if (maxsub[i] <= n / 2) {
                // 找到一个重心节点
                centers[m++] = i;
            }
        }
        if (m == 2) {
            // 这棵树有2个重心
            find(centers[1], centers[0]);
        }
        return m;
    }
 }
